home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / A.D. Software / OOFILE / Buildable, limited OOFILE / samples / ooftst21.cpp < prev   
C/C++ Source or Header  |  1996-04-01  |  4KB  |  160 lines

  1. #include "oofile.hpp"
  2.  
  3. DECLARE_CLASS(dbTest21)
  4.     dbChar        f1;
  5.     dbUlong        f2;
  6.     dbReal        f3;  
  7.     static dbSorter sort123;
  8.     
  9.     dbTest21() : f1(20, "F1", kIndexed),
  10.                 f2("F2", kIndexed),
  11.                 f3("F3", kIndexed)
  12. {};
  13.     
  14. // my own data entry procedures
  15.     void Add(const char *tf1,const unsigned long tf2,const double tf3);
  16.     void AddTestData();
  17. };
  18.  
  19.  
  20. void dbTest21::Add(const char *tf1,const unsigned long tf2,const double tf3)
  21. {
  22.     newRecord();
  23.     f1=tf1;
  24.     f2=tf2;
  25.     f3=tf3;
  26.     saveRecord();
  27. }
  28.  
  29.  
  30. void dbTest21::AddTestData()
  31. {
  32.     Add("Denton",2000,3.5);
  33.     Add("Taylor",2000,4.5);
  34.     Add("Taylor",3000,5.5);
  35.     Add("Taylor",2000,3.5);
  36.     Add("Denton",1000,1.5);
  37.     Add("Underwood",1000,1.5);
  38.     Add("Zaphod",5000,5.5);
  39. }
  40.  
  41.  
  42.  
  43. // test some specific sort bugs reported by Liam
  44. class dbArchive : public dbTable { 
  45.  
  46.     OOFILE_METHODS(dbArchive)  
  47.  
  48. public:  // table columns for all archives
  49.     dbLong    Size; // in bytes
  50.     dbDate    Date;
  51.     dbChar    FileName;
  52.     dbSorter arcSort;
  53.     
  54.     dbArchive() : 
  55.         Size("Size", kIndexed),
  56.         Date("Date Created"),
  57.         FileName(80, "File Name", kIndexCompress)
  58.     {
  59.         arcSort >> Date << FileName;
  60.     };
  61.     void AddTestData();
  62. };
  63.  
  64. void
  65. dbArchive::AddTestData() {
  66.     dbDate::sDefaultDateOrder = dbDate::orderMDY;
  67.     
  68.     ostrstream oss;
  69.     oss << "153357\tMar 15 1996\tart/zine/real-macoy-11.hqx" << endl
  70.         << "288387\tMar 15 1996\tart/zine/real-macoy-12.hqx" << endl
  71.         << "205018\tMar 15 1996\tart/zine/real-macoy-13.hqx" << endl
  72.         << "448459\tMar 15 1996\tart/zine/real-macoy-14.hqx" << endl
  73.         << "6096\tMar 16 1996\tdev/cw LMouser.hqx" << endl
  74.         << "190561\tMar 16 1996\tdev/cw cw-pascal-tcl-port-10.hqx" << endl;
  75.     istream is(oss.rdbuf());
  76.     is >> *this;
  77. }
  78.  
  79. // static sort member
  80.     dbSorter         dbTest21::sort123;
  81.  
  82. int main()
  83. {
  84.     cout << "OOFILE Validation Suite - Test 21\n"
  85.          << "This tests the string contains functions\n"
  86.          << "and the nested sorts\n\n";
  87.     
  88.     dbConnect_ctree  theDB;
  89.     dbTest21          dbTest;
  90.     dbArchive         Archive;
  91.     
  92. // init static sort    
  93.     dbTest21::sort123 << dbTest.f1 << dbTest.f2 << dbTest.f3;  
  94.  
  95.     if (dbConnect::fileExists("ooftst21.db"))
  96.         theDB.openConnection("ooftst21.db");
  97.     else {
  98.         theDB.newConnection("ooftst21.db");
  99.         dbTest.AddTestData();
  100.         Archive.AddTestData();
  101.     }
  102.     cout << "Listing All Records" << endl << endl;
  103.     cout << dbTest;
  104.     
  105.     cout << endl << "Test 'Contains Any' Search - searching for 'ta', 'en' or 'wood'" << endl << endl;
  106.     dbTest.searchSelContainsAnyDelimited(dbTest.f1, "ta,en,wood",',');
  107.     cout << dbTest;
  108.     
  109.     cout << endl << "Test 'Contains All' Search - searching for 'wood', 'u' and 'de'" << endl << endl;
  110.     dbTest.searchSelContainsAllDelimited(dbTest.f1, "wood,u,de",',');
  111.     cout << dbTest;
  112.     
  113.     dbTest.selectAll();
  114.     
  115.     cout << endl <<"Testing Nested sort - sorting by all fields, 1 - 2 - 3" << endl << endl;
  116.     dbTest.setSortOrder(dbTest.sort123);
  117.     cout << dbTest;
  118.  
  119.     cout << endl <<"Testing Nested sort on 1st all same value - sorting by all fields, 1 - 2 - 3" << endl << endl;
  120.     dbTest.search(dbTest.f1.startsWith("Tay"));
  121.     cout << dbTest;
  122.  
  123.     dbTest.selectAll();
  124.     
  125.     cout << endl <<"Testing Nested sort - sorting by all fields, 2 - 1 - 3" << endl << endl;
  126.     dbSorter sort213;
  127.     sort213 << dbTest.f2 << dbTest.f1 << dbTest.f3;
  128.     dbTest.setSortOrder(sort213);
  129.     cout << dbTest;
  130.  
  131.     cout << endl << "now reversing the second sort item in the above test" << endl << endl;
  132.     dbTest.setSortOrder(dbSorter() << dbTest.f2 << reverse(dbTest.f1) << dbTest.f3);
  133.     cout << dbTest;
  134.     
  135.     cout << endl << "Testing suspended sorts and cloning selections (fields 123)" << endl;
  136.     dbTest.setSortOrder(dbTest.sort123);
  137.     dbTest.suspendSorting();
  138.     dbTest.search(dbTest.f1.startsWith("Tay"));
  139.     cout << "Unsorted..." << endl << dbTest << endl;
  140.  
  141.     dbTest21 cloned(dbTest);  // should have same sort order, still suspended
  142.  
  143.     dbTest.resumeSorting();
  144.     cout << "Sorted..." << endl << dbTest << endl;
  145.         
  146.     cout << "Unsorted clone..." << endl << cloned << endl;
  147.     cloned.resumeSorting();
  148.     cout << "Sorted clone..." << endl << cloned << endl;
  149.     
  150.  
  151.     cout << "Now testing some additional multiple field sort bugs" << endl;
  152.     cout << "Unsorted" << endl << Archive << endl;
  153.     
  154.     Archive.setSortOrder(Archive.arcSort);
  155.     cout << ">> Date << FileName" << endl << Archive << endl;
  156.  
  157.     cout << endl <<"Test Completed" << endl;
  158.     
  159.     return EXIT_SUCCESS;